package com.proyemp.prueba.rafa;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class SolverFactory{
    
    public static AbstractSolver getSolver(AbstractContract contrato){
        
    	String tipoContrato = contrato.getClass().toString(); // obtengo el tipo del contrato en runtime
    	String contratoString = tipoContrato.substring(tipoContrato.indexOf(" "));
        String nombreSolver = PropertyReader.getReader().getProperty( contratoString.trim() );
        Object salida = null;
        
		try {
			Class c = Class.forName( nombreSolver );			// reflection
			Constructor constructor = c.getConstructor();       // reflection
	        salida = constructor.newInstance();					// reflection
	        
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		}         

        return (AbstractSolver) salida;

    }

}